package ${package.Controller};

import org.springframework.web.bind.annotation.RequestMapping;
import javax.annotation.Resource;
import ${package.Entity}.${entity};
import ${package.Service}.${table.serviceName};
import com.yy.permissions_general.common.aopSubmit.aop.NoRepeatSubmit;
import com.yy.permissions_general.module.system.aopLog.aop.MyLog;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.RestController;
import com.yy.permissions_general.utils.ResultUtil;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List;


/**
 * <p>
 * ${table.comment!}前端控制器
 * </p>
 *
 * @author ${author}
 * @since ${date}
 */
@RestController
@RequestMapping("/${lowerEntityName}")
public class ${table.controllerName} {

    @Resource
    private ${table.serviceName} ${lowerServiceName};

    /**
    * 查询列表
    * @param ${lowerEntityName}
    * @param limit
    * @param page
    * @return
    */
    @MyLog("查询列表")
    @NoRepeatSubmit(key="${lowerEntityName}.list")
    @RequestMapping("/list")
    public ResultUtil list(${entity} ${lowerEntityName},@RequestParam(value = "limit",defaultValue = "999999")int limit, @RequestParam(value = "page",defaultValue = "0")int page) {
      return ResultUtil.buildPagination(${lowerServiceName}.selectPageList(${lowerEntityName},limit,page));
    }

    /**
    * 新增数据
    * @param ${lowerEntityName}
    * @return
    */
    @MyLog("新增数据")
    @NoRepeatSubmit(key="${lowerEntityName}.add ${entity}")
    @PreAuthorize("hasPermission('/${lowerEntityName}/add${entity}','${lowerEntityName}:add${entity}')")
    @RequestMapping("/add${entity}")
    public ResultUtil add${entity}(${entity} ${lowerEntityName}) {
        ${lowerServiceName}.add${entity}(${lowerEntityName});
        return ResultUtil.success();
    }

    /**
    * 修改数据
    * @param ${lowerEntityName}
    * @return
    */
    @MyLog("修改数据")
    @NoRepeatSubmit(key="${lowerEntityName}.edit${entity}")
    @PreAuthorize("hasPermission('/${lowerEntityName}/edit${entity}','${lowerEntityName}:edit${entity}')")
    @RequestMapping("/edit${entity}")
    public ResultUtil edit${entity}(${entity} ${lowerEntityName}) {
        ${lowerServiceName}.edit${entity}(${lowerEntityName});
        return ResultUtil.success();
    }

    /**
    * 查看详情
    * @param ${keyPropertyName}
    * @return
    */
    @MyLog("查看详情")
    @RequestMapping("/detail${entity}")
    public ResultUtil detail${entity}(${keyPropertyType} ${keyPropertyName}) {
        ${entity} ${lowerEntityName} = ${lowerServiceName}.getDetailsById(${keyPropertyName});
        return ResultUtil.success(${lowerEntityName});
    }

    /**
    * 根据ID删除记录
    * @param ${keyPropertyName}
    * @return
    */
    @MyLog("删除")
    @NoRepeatSubmit(key="${lowerEntityName}.delete")
    @PreAuthorize("hasPermission('/${lowerEntityName}/delete','${lowerEntityName}:delete')")
    @RequestMapping("/delete")
    public ResultUtil delete(${keyPropertyType} ${keyPropertyName}) {
        ${lowerServiceName}.deleteById(${keyPropertyName});
        return ResultUtil.success();
    }

    /**
    * 批量删除数据
    * @param ids ID集合
    * @return
    */
    @MyLog("批量删除")
    @NoRepeatSubmit(key="${lowerEntityName}.deleteBatch")
    @PreAuthorize("hasPermission('/${lowerEntityName}/deleteBatch','${lowerEntityName}:deleteBatch')")
    @RequestMapping("/deleteBatch")
    public ResultUtil deleteBatch(@RequestParam(value = "ids[]",required = true) List<Long> ids) {
        ${lowerServiceName}.deleteBatch(ids);
        return ResultUtil.success();
    }

}
